import { NextRequest, NextResponse } from 'next/server'
import { registerUser } from '@/lib/auth-service'

export async function POST(request: NextRequest) {
  try {
    const body = await request.json()
    const { email, password, name } = body

    const result = await registerUser({ email, password, name })

    if (result.success) {
      return NextResponse.json({
        success: true,
        user: result.user,
        message: '注册成功'
      })
    } else {
      return NextResponse.json({
        success: false,
        error: result.error
      }, { status: 400 })
    }
  } catch (error) {
    console.error('注册API错误:', error)
    return NextResponse.json({
      success: false,
      error: '服务器内部错误'
    }, { status: 500 })
  }
}